<?php
require('../../../global.php');
//进入页面后先判断是否有访问权限
checkAdminAuthorizeAndJump('member.edit');

if(isset($_GET['id'])){
    $member = $db->get('tb_member', '*', array('tbid' => $_GET['id']));
}
?>
<!DOCTYPE html>
<html>
<head>
    <?php require('admin/_head.php'); ?>
    <title>会员管理 - <?php echo getconfig('title'); ?>管理后台</title>

    <link href="<?php echo SITEROOTURL; ?>/admin/js/plugins/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h3>
                    <button type="button" class="btn btn-white btn-sm closelayer">返回</button>
                    查看会员详细信息
                </h3>
            </div>
            <div class="ibox-content">
                <div class="row row-lg">
                    <div class="col-sm-12">
                        <form class="form-horizontal" id="editForm" action="ajax.php">
                            <input type="hidden" name="ac" value="edit">
                            <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>">
                            <div class="form-group">
                                <label class="col-sm-2 control-label">头像</label>
                                <div class="col-sm-10">
                                    <p class="form-control-static"><?php echo $member['avatar'] ? '<img class="img-thumbnail" src="'.SITEROOTURL.$member['avatar'].'" />' : '【未上传图片】' ?></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">微信昵称</label>
                                <div class="col-sm-10">
                                    <p class="form-control-static"><?php echo $member['nickname']; ?></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">真实姓名</label>
                                <div class="col-sm-10">
                                    <p class="form-control-static"><?php echo $member['realname']; ?></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">手机号码</label>
                                <div class="col-sm-10">
                                    <p class="form-control-static"><?php echo $member['mobile']; ?></p>
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">家庭角色</label>
                                <div class="col-sm-10">
                                     <input type="text" name="family_role" id="family_role" placeholder="请输入家庭角色" class="form-control" value="<?php echo $member['family_role']; ?>" dataType="*" nullmsg="请输入家庭角色" errormsg="请输入家庭角色">
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">所在城市</label>
                                <div class="col-sm-10">
                                    <input type="text" name="city" id="city" placeholder="请输入所在城市" class="form-control" value="<?php echo $member['city']; ?>" dataType="*" nullmsg="请输入所在城市" errormsg="请输入所在城市">
                                   
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">详细地址</label>
                                <div class="col-sm-10">
                                    <input type="text" name="address" id="address" placeholder="请输入详细地址" class="form-control" value="<?php echo $member['address']; ?>" dataType="*" nullmsg="请输入详细地址" errormsg="请输入详细地址">
                                    
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">孩子姓名</label>
                                <div class="col-sm-10">
                                    <input type="text" name="child_name" id="child_name" placeholder="请输入孩子姓名" class="form-control" value="<?php echo $member['child_name']; ?>" dataType="*" nullmsg="请输入孩子姓名" errormsg="请输入孩子姓名">
                                  
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">孩子年龄</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="child_age" dataType="*" nullmsg="请选择周岁">
                                        <option value='' > 请选择周岁 </option>
                                        <option value='7' <?php echo 7==$member['child_age']?'selected':''; ?>> 7周岁 </option>
                                        <option value='8' <?php echo 8==$member['child_age']?'selected':''; ?>> 8周岁 </option>
                                        <option value='9' <?php echo 9==$member['child_age']?'selected':''; ?>> 9周岁 </option>
                                        <option value='10' <?php echo 10==$member['child_age']?'selected':''; ?>> 10周岁 </option>
                                        <option value='11' <?php echo 11==$member['child_age']?'selected':''; ?>> 11周岁 </option>
                                        <option value='12' <?php echo 12==$member['child_age']?'selected':''; ?>> 12周岁 </option>
                                        <option value='13' <?php echo 13==$member['child_age']?'selected':''; ?>> 13周岁 </option>
                                      
                                   </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">孩子性别</label>
                                <div class="col-sm-10">
                                    <select class="form-control" name="child_sex" dataType="*" nullmsg="请选择性别">
                                        <option value='' > 请选择性别 </option>
                                        <option value='1' <?php echo 1==$member['child_sex']?'selected':''; ?>> 男 </option>
                                        <option value='2' <?php echo 2==$member['child_sex']?'selected':''; ?>> 女 </option>
                                    </select>
                                    
                                </div>
                            </div>


                            <div class="form-group">
                                <label class="col-sm-2 control-label">注册时间</label>
                                <div class="col-sm-10">
                                    <p class="form-control-static"><?php echo $member['createtime']; ?></p>
                                </div>
                            </div>
                            <div class="form-group">
                                <label class="col-sm-2 control-label">上次登录时间</label>
                                <div class="col-sm-10">
                                    <p class="form-control-static"><?php
                                        $whereLoginTimeWhere['AND']['member_id'] = $_GET['id'];
                                        $whereLoginTimeWhere['ORDER']['tbid'] = 'DESC';
                                        $last_login_time = $db->get('login_log', 'dt', $whereLoginTimeWhere);
                                        $last_login_time = ($last_login_time)? $last_login_time : '';


                                     echo $last_login_time; ?></p>
                                </div>
                            </div>

                            <div class="hr-line-dashed"></div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">会员来源</label>
                                <div class="col-sm-10">
                                    <p class="form-control-static">
                                        <?php  echo 1 == $member['type'] ?'专业测试':'专家预约';?>

                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">测试次数</label>
                                <div class="col-sm-10">
                                    <p class="form-control-static">
                                <?php 
                                    $testNumber = $db->count('tb_test_result', 'tbid', array('member_id' => $_GET['id']));
                                    echo $testNumber;
                                ?>

                                    </p>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">预约次数</label>
                                <div class="col-sm-10">
                                    <p class="form-control-static">
                                <?php 

                                    $reserveWhere['AND']['member_id'] = $_GET['id'];
                                    $reserveWhere['AND']['type'] = 3;
                                    $reserveNumber = $db->sum('tb_order', 'reserve_number', $reserveWhere);
                                    echo $reserveNumber;
                                ?>

                                    </p>
                                </div>
                            </div>

                            <div class="form-group">
                                <label class="col-sm-2 control-label">面询次数</label>
                                <div class="col-sm-10">
                                    <p class="form-control-static">
                                <?php 

                                    $reserveWhere['AND']['member_id'] = $_GET['id'];
                                    $reserveWhere['AND']['type'] = 3;
                                    $order = $db->select('tb_order', '*', $reserveWhere);

                                     $faceNumber = 0;
                                    if (!empty($order)) {
                                        foreach ($order as $key => $value) {
                                            $isTest = $db->get('tb_expert_reserve', 'is_test', array('order_id' => $value['tbid']));
                                            if (true == $isTest) {
                                                $faceNumber++;
                                            }

                                        }

                                    }
                                    echo $faceNumber;
                                ?>

                                    </p>
                                </div>
                            </div>

                             <div class="hr-line-dashed"></div>
                            <div class="form-group">
                                <div class="col-sm-4 col-sm-offset-2">
                                    <button class="btn btn-primary btn-lg" type="submit" id="btn-submit">保存内容</button>
                                    <button class="btn btn-white btn-lg closelayer" type="button">取消</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php require('admin/_js.php'); ?>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/content.js?v=1.0.0"></script>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/plugins/validform/Validform_min.js"></script>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/plugins/validform/Validform_Datatype.js"></script>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/plugins/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/plugins/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="<?php echo SITEROOTURL; ?>/admin/js/jbase64.js"></script>
    <script>
    $(function(){
        var closeLayer = function(){
            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            parent.closeLayer(index);
        }
        $('.closelayer').click(function(event){
            closeLayer();
        });
        var form = $('#editForm').Validform({
            btnSubmit: '#btn-submit',
            postonce: false,
            showAllError: true,
            //msg：提示信息;
            //o:{obj:*,type:*,curform:*}, obj指向的是当前验证的表单元素（或表单对象），type指示提示的状态，值为1、2、3、4， 1：正在检测/提交数据，2：通过验证，3：验证失败，4：提示ignore状态, curform为当前form对象;
            //cssctl:内置的提示信息样式控制函数，该函数需传入两个参数：显示提示信息的对象 和 当前提示的状态（既形参o中的type）;
            tiptype: function(msg, o){
                if(!o.obj.is('form')){//验证表单元素时o.obj为该表单元素，全部验证通过提交表单时o.obj为该表单对象;
                    var B = o.obj.parents('.form-group');
                    var T = B.find('.help-block');
                    if(o.type == 2){
                        B.removeClass('has-error').addClass('has-success');
                        T.html('');
                    }else{
                        B.removeClass('has-success').addClass('has-error');
                        T.html("<i class='fa fa-times-circle'></i> " + msg);
                    }
                }
            },
            ajaxPost: true,
            callback: function(data){
                if(data.status == 'y'){
                    parent.swal('操作成功', '', 'success');
                    closeLayer();
                }else{
                    swal('操作失败', '', 'error');
                }
            }
        });
    });

    </script>
</body>
</html>
